package top.lixunda.ecommerce.server.good.api.entity.vo;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.beans.BeanUtils;
import top.lixunda.common.utils.ObjectValidators;
import top.lixunda.ecommerce.server.good.api.entity.db.EnshrineGoodsDO;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 返回商品收藏数据到前端
 * @author Xumda
 * @version time:2020/1/7 15:25
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class EnshrineGoodVO extends EnshrineGoodsDO {

    /**
     * 转换数据
     *
     * @param enshrineGoodsDO 商品收藏DO
     * @return 商品收藏VO
     */
    public static EnshrineGoodVO fromEnshrineGoodsDO(EnshrineGoodsDO enshrineGoodsDO){
        if(enshrineGoodsDO == null){
            return null;
        }
        EnshrineGoodVO vo = new EnshrineGoodVO();
        BeanUtils.copyProperties(enshrineGoodsDO, vo);
        return vo;
    }

    /**
     * 转换数据
     *
     * @param list 商品收藏DO
     * @return 商品收藏VO
     */
    public static List<EnshrineGoodVO> fromEnshrineGoodsDO(List<EnshrineGoodsDO> list){
        if(ObjectValidators.isEmpty(list)){
            return Collections.emptyList();
        }
        return list.stream()
                .map(EnshrineGoodVO::fromEnshrineGoodsDO)
                .collect(Collectors.toList());
    }

}
